#include<iostream>
#include<string.h>
#include<cmath>
using namespace std;
int a[8] = { 0 };
int c[8] = { 0 };
bool ok(int k)
{
	if (k == 0)return true;
	for (int i = 0; i < k; i++)
		if (a[i] == a[k] || abs(a[i] - a[k]) == abs(i - k))return false;
	return true;
}
void print()
{
	cout << "---------------------------------" << endl;
	for (int i = 0; i < 8; i++)
	{
		for (int j = 0; j < 8; j++)
		{
			if (j == 0)cout << "|";
			if (a[i] == j)cout << " Q |";
			else cout << "   |";
		}
		cout << endl << "---------------------------------" << endl;
	}
	cout << endl << endl << endl;
}
int main()
{
	int cnt = 0;
	int k = 0;
	while (k >= 0)
	{
		while (c[k] <= 7)
		{
			a[k] = c[k]++;
			if (ok(k) && k < 7)k++;
			else if (ok(k) && k == 7)
			{
				print();
				cnt++;
			}
		}
		a[k] = 0; c[k] = 0; k--;
	}
	cout << "" << cnt << endl;
	return 0;
}
